// 属性相关的API
import request from '@/utils/request'
import type { AttrListResponse, AttrObj, CategoryResponse } from './type'

enum API {
  // 获取一级分类接口地址
  C1_URL = '/admin/product/getCategory1',
  // 获取二级分类接口地址
  C2_URL = '/admin/product/getCategory2',
  // 获取三级分类接口地址
  C3_URL = '/admin/product/getCategory3',
  // 获取属性列表的接口地址
  ATTR_URL = '/admin/product/attrInfoList',
  // 添加/修改已有属性的接口地址
  ADD_OR_UPDATE_URL = '/admin/product/saveAttrInfo',
  // 删除已有属性的接口地址
  DELETE_URL = '/admin/product/deleteAttr',
}
// 获取一级分类的接口方法
export const reqC1 = () => request.get<any, CategoryResponse>(API.C1_URL)
// 获取二级分类的接口方法
export const reqC2 = (category1id: number) =>
  request.get<any, CategoryResponse>(API.C2_URL + `/${category1id}`)
// 获取三级分类的接口方法
export const reqC3 = (category2id: number) =>
  request.get<any, CategoryResponse>(API.C3_URL + `/${category2id}`)
// 获取属性列表的接口方法
export const reqAttr = (c1Id: number, c2Id: number, c3Id: number) =>
  request.get<any, AttrListResponse>(API.ATTR_URL + `/${c1Id}/${c2Id}/${c3Id}`)
// 新增/修改商品列表的方法(根据有无id属性区别新增/修改)
export const reqAddOrUpdate = (data: AttrObj) =>
  request.post<any, any>(API.ADD_OR_UPDATE_URL, data)
// 删除已有属性的方法
export const reqDeleteAttr = (id: number) =>
  request.delete<any, any>(API.DELETE_URL + `/${id}`)
